import request from '@/config/axios'

export interface EvalAttendanceRecordVO {
  id?: number
  planId: number
  candidateInfoId: number
  attendanceDate: string
  attendanceType: number
  checkInTime?: string
  checkOutTime?: string
  attendanceStatus: number
  attendanceComments?: string
  createTime?: Date
}

export interface EvalAttendanceRecordPageReqVO extends PageParam {
  planId?: number
  candidateInfoId?: number
  attendanceDate?: string[]
  attendanceType?: number
  attendanceStatus?: number
  createTime?: Date[]
}

export interface EvalAttendanceBatchCreateReqVO {
  planId: number
  candidateInfoIds: number[]
  attendanceDate: string
  attendanceType: number
}

export interface EvalAttendanceStatisticsVO {
  planId: number
  totalCandidates: number
  presentCount: number
  absentCount: number
  lateCount: number
  attendanceRate: number
}

// 查询考勤记录分页
export const getAttendanceRecordPage = (params: EvalAttendanceRecordPageReqVO) => {
  return request.get({ url: '/eval/attendance-record/page', params })
}

// 查询考勤记录详情
export const getAttendanceRecord = (id: number) => {
  return request.get({ url: '/eval/attendance-record/get?id=' + id })
}

// 新增考勤记录
export const createAttendanceRecord = (data: EvalAttendanceRecordVO) => {
  return request.post({ url: '/eval/attendance-record/create', data })
}

// 修改考勤记录
export const updateAttendanceRecord = (data: EvalAttendanceRecordVO) => {
  return request.put({ url: '/eval/attendance-record/update', data })
}

// 删除考勤记录
export const deleteAttendanceRecord = (id: number) => {
  return request.delete({ url: '/eval/attendance-record/delete?id=' + id })
}

// 导出考勤记录
export const exportAttendanceRecord = (params: EvalAttendanceRecordPageReqVO) => {
  return request.download({ url: '/eval/attendance-record/export-excel', params })
}

// 根据计划ID获得考勤记录列表
export const getAttendanceRecordListByPlanId = (planId: number) => {
  return request.get({ url: '/eval/attendance-record/list-by-plan?planId=' + planId })
}

// 根据参评人员ID获得考勤记录列表
export const getAttendanceRecordListByCandidateId = (candidateInfoId: number) => {
  return request.get({ url: '/eval/attendance-record/list-by-candidate?candidateInfoId=' + candidateInfoId })
}

// 批量创建考勤记录
export const batchCreateAttendanceRecord = (data: EvalAttendanceBatchCreateReqVO) => {
  return request.post({ url: '/eval/attendance-record/batch-create', data })
}

// 签到
export const checkIn = (planId: number, candidateInfoId: number) => {
  return request.post({ url: '/eval/attendance-record/check-in', data: { planId, candidateInfoId } })
}

// 签退
export const checkOut = (planId: number, candidateInfoId: number) => {
  return request.post({ url: '/eval/attendance-record/check-out', data: { planId, candidateInfoId } })
}

// 获取考勤统计
export const getAttendanceStatistics = (planId: number): Promise<EvalAttendanceStatisticsVO> => {
  return request.get({ url: '/eval/attendance-record/statistics?planId=' + planId })
}

// 获取考勤汇总报表
export const getAttendanceSummaryReport = (planId: number) => {
  return request.get({ url: '/eval/attendance-record/summary-report?planId=' + planId })
}

// 导出考勤汇总报表
export const exportAttendanceSummaryReport = (planId: number) => {
  return request.download({ url: '/eval/attendance-record/export-summary-report?planId=' + planId })
}
